package com.kmxd.ams.core.satoken;

import cn.dev33.satoken.stp.StpInterface;
import com.kmxd.ams.core.common.bo.SysRoleBO;
import com.kmxd.ams.core.util.SecurityUtil;
import com.google.common.collect.Lists;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 自定义SaToken权限验证
 *
 * @author admin
 */
@Component
public class CustomStpInterface implements StpInterface {
  @Override
  public List<String> getPermissionList(Object loginId, String loginType) {
    return Lists.newArrayList(SecurityUtil.getLoginUser().getPermissions());
  }

  @Override
  public List<String> getRoleList(Object loginId, String loginType) {
    return SecurityUtil.getLoginUser().getSysUser().getRoles().stream()
        .map(SysRoleBO::getRoleCode)
        .collect(Collectors.toList());
  }
}
